//
//  UIButton+AWTheme.m
//  changeShin
//
//  Created by Alan Wang on 2019/3/26.
//  Copyright © 2019 Alan Wang. All rights reserved.
//

#import "UIButton+AWTheme.h"
#import "NSObject+AWTheme.h"

@implementation UIButton (AWTheme)
-(void)AWTheme_TitleColorForKey:(NSString*)key forState:(UIControlState)state{
    AWweakify(self)
    [self saveBlok:^{
        AWstrongify(self)
        UIColor * color = [[AWThemeManager shareInstance] colorForKey:key];
        if (color) {
          [self setTitleColor:color forState:state];
        }
    } forKey:[NSString stringWithFormat:@"setTitleColor:forState:%lu",(unsigned long)state]];
}
-(void)AWTheme_ImageForKey:(NSString*)key forState:(UIControlState)state{
    AWweakify(self)
    [self saveBlok:^{
        AWstrongify(self)
        UIImage * image = [[AWThemeManager shareInstance] imageForKey:key];
        if (image) {
            [self setImage:image forState:state];
        }
    } forKey:[NSString stringWithFormat:@"setImage:forState:%lu",(unsigned long)state]];
}

-(void)AWTheme_BackgroundImageForKey:(NSString*)key forState:(UIControlState)state{
    AWweakify(self)
    [self saveBlok:^{
        AWstrongify(self)
        UIImage * image = [[AWThemeManager shareInstance] imageForKey:key];
        if (image) {
            [self setBackgroundImage:image forState:state];
        }
    } forKey:[NSString stringWithFormat:@"setBackgroundImage:forState:%lu",(unsigned long)state]];
}

-(void)AWTheme_ImageForName:(NSString*)key buddleName:(NSString*)buddleName forState:(UIControlState)state{
    AWweakify(self)
    [self saveBlok:^{
        AWstrongify(self)
        UIImage * image = [[AWThemeManager shareInstance] imageForName:key fromBudddle:buddleName];
        if (image) {
            [self setImage:image forState:state];
        }
    } forKey:[NSString stringWithFormat:@"setImage:forState:%lu",(unsigned long)state]];
}

-(void)AWTheme_BackgroundImageForName:(NSString*)key buddleName:(NSString*)buddleName forState:(UIControlState)state{
    AWweakify(self)
    [self saveBlok:^{
        AWstrongify(self)
        UIImage * image = [[AWThemeManager shareInstance] imageForName:key fromBudddle:buddleName];
        if (image) {
            [self setBackgroundImage:image forState:state];
        }
    } forKey:[NSString stringWithFormat:@"setBackgroundImage:forState:%lu",(unsigned long)state]];
}



@end
